﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ShoppingApp
{
    public partial class SessionVariables2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["address"] != null)
            {
                this.Label2.Text = (string)Session["address"];
            }
            else
            {
                this.Label2.Text = null;
            }

            if (Session["person1"] != null)
            {
                Person p1 = (Person)Session["person1"];
                this.Label3.Text = p1.FirstName + " " + p1.LastName;
            }
            else
            {
                this.Label3.Text = null;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

            //Needed because postback is executet earlier then abandon
            Response.Redirect(Request.Url.ToString());
        }
    }
}